package com.qing;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * Created by wuliao on 2017/9/12.
 */
public class HTableUtil {


    private static HTable table;
    private static Configuration conf;

    static {
        conf = HBaseConfiguration.create();
        conf.set("fs.default.name", "hbase:8020");
        conf.set("hbase.zookeeper.quorum", "hbase");
        try {
            table = new HTable(conf, "log");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static Configuration getConf() {
        return conf;
    }

    public static HTable getHTable(String tableName) {
        if (table == null) {
            try {
                table = new HTable(conf, tableName);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return table;
    }

    public static byte[] gB(String name) {
        return Bytes.toBytes(name);
    }

}
